from django.db import models

# Create your models here.
class Grade(models.Model):
    gname=models.CharField(max_length=32,verbose_name="等级")

    class Meta:
        db_table='grade'

    def __str__(self):
        return self.gname

class User(models.Model):
    username=models.CharField(max_length=32)
    password=models.CharField(max_length=500)
    status=models.BooleanField(default=0)
    email=models.EmailField(max_length=60)

    class Meta:
        db_table='user'

    def __str__(self):
        return self.username


class UserInfo(models.Model):
    name=models.CharField(max_length=32)
    phone=models.CharField(max_length=32)
    idcard=models.CharField(max_length=32)
    QQ=models.CharField(max_length=32)
    address=models.CharField(max_length=100)
    user=models.OneToOneField('User',on_delete=models.CASCADE)

    class Meta:
        db_table='userinfo'

    def __str__(self):
        return self.name


class Author(models.Model):
    aname=models.CharField(max_length=32)
    astatus=models.BooleanField(default=0)
    user=models.OneToOneField('User',on_delete=models.CASCADE)
    class Meta:
        db_table='author'

    def __str__(self):
        return self.aname

class Cate(models.Model):
    cate_name=models.CharField(max_length=32)

    class Meta:
        db_table='cate'

    def __str__(self):
        return self.cate_name

class Fiction(models.Model):
    fiction_name=models.CharField(max_length=80)
    author=models.OneToOneField('Author',on_delete=models.CASCADE)
    price=models.DecimalField(max_digits=9,decimal_places=2)
    time=models.DateTimeField(auto_now_add=True)
    describe=models.CharField(max_length=1000)
    read=models.IntegerField(default=0)
    cate=models.OneToOneField('Cate',on_delete=models.CASCADE)
    img=models.ImageField(upload_to='static')

    class Meta:
        db_table='fiction'

    def __self__(self):
        return self.fiction_name

class Section(models.Model):
    section_name=models.CharField(max_length=32)
    content=models.CharField(max_length=9999)
    fiction=models.OneToOneField('Fiction',on_delete=models.CASCADE)

    class Meta:
        db_table='section'

    def __self__(self):
        return self.section_name




















